<?php

use common\models\user\SignupModel;
use peng\enums\ValidatorCode;

/**
 * 测试-用户注册
 * 
 * @author peng.huang
 */
class SignupTest extends PHPUnit_Framework_TestCase {

    private $_biz;

    public function setUp() {
        $this->_biz = new common\biz\UserBiz();
    }

    /**
     * @dataProvider addProvider
     */
    public function testSignup($entity, $expected) {
        $this->_biz->signup($entity, FALSE);
        $this->assertEquals($expected, $entity->getValidatorCode(), iconv('utf-8', 'gbk', $entity->getErrorSummary(FALSE)));
    }

    /**
     * 数据提供器
     * 
     * @return array
     */
    public function addProvider() {
        $arr = array();

        // 第1组
        $entity = new SignupModel();
        $arr[] = array($entity, ValidatorCode::REQUIRED | ValidatorCode::STRING | ValidatorCode::RANGE);

        // 第2组
        $entity = new SignupModel();
        $entity->loginname = 'xxx';
        $entity->password = 'xxx';
        $entity->verifyCode = 'yyy';
        $arr[] = array($entity, ValidatorCode::STRING | ValidatorCode::RANGE | ValidatorCode::COMPARE);

        // 第3组
        $entity = new SignupModel();
        $entity->loginname = 'xxx';
        $entity->password = 'xxx';
        $entity->cfmpwd = 'xxx';
        $entity->rtype = '1';
        $entity->utype = '1';
        $entity->verifyCode = 'yyy';
        $arr[] = array($entity, ValidatorCode::STRING);

        // 第4组
        $entity = new SignupModel();
        $entity->loginname = '12345678902';
        $entity->password = '123456';
        $entity->cfmpwd = '123456';
        $entity->rtype = '0';
        $entity->utype = '0';
        $entity->verifyCode = '1';
        $arr[] = array($entity, ValidatorCode::EXISTS);

        // 第5组
        $entity = new SignupModel();
        $entity->loginname = '12345678902';
        $entity->password = '123456';
        $entity->cfmpwd = '123456';
        $entity->rtype = '0';
        $entity->utype = '0';
        $entity->verifyCode = '1';
        $arr[] = array($entity, ValidatorCode::EXISTS);

        // 第6组
        $entity = new SignupModel();
        $entity->loginname = '123@qq.com';
        $entity->password = '123456';
        $entity->cfmpwd = '123456';
        $entity->rtype = '1';
        $entity->utype = '0';
        $entity->verifyCode = '1';
        $arr[] = array($entity, ValidatorCode::EXISTS);

        return $arr;
    }

}
